function output = evaluate_cf(pars,M_full,W_full,Nu,verbose,fignum)     
    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Vector of fixed parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Rho                                     = NaN(numel(Nu.fixed_pars),1);
for p=1:numel(Nu.fixed_pars)
        Rho(p)                                  = pars.(Nu.fixed_pars{p});
end 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Vector of targeted parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Xi                                      = NaN(numel(Nu.targeted_pars),1);
for p=1:numel(Nu.targeted_pars)
        Xi(p)                                  = pars.(Nu.targeted_pars{p});
end  

%%%%%%%%%%%%%%
% Constraints
%%%%%%%%%%%%%%
A                                       = Nu.A;
b                                       = Nu.b;
lb                                      = Nu.lb;
ub                                      = Nu.ub; 
if any(A*Xi > b)||any( any( Xi > ub ) )||any( any( Xi < lb ) )
        save('runs/evaluate_v2_call.mat');
        error('Error: point violates the local constraints \n');
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compute objective and moments at point
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
XiFinal                                 = Xi;
FlagFinal                               = 1;
FevalsFinal                             = 1;
if nargin > 5
Dummy                                   = produce_moments_cf(XiFinal,Rho,Nu,1,fignum);
else
Dummy                                   = produce_moments_cf(XiFinal,Rho,Nu);
end
OutputFinal.M                           = Dummy.M;
OutputFinal.X_monthly                   = Dummy.X_monthly;
OutputFinal.M_monthly                   = Dummy.M_monthly;
ObjFinal                                = SMM_obj( XiFinal, Rho, Nu, M_full, W_full, Nu.log_targeted_moments, 0 );
ObjFinalAllMoms                         = SMM_obj( XiFinal, Rho, Nu, M_full, W_full, true(size(Nu.log_targeted_moments)), 0 );
XiFinalAllPars                          = [pars.xi,pars.sigma,pars.k,XiFinal(1),XiFinal(4),XiFinal(5)]';

%%%%%%%%%%%%%%%
% Print output
%%%%%%%%%%%%%%%
if verbose 
    Table6                                  = table(num2str(XiFinalAllPars,'%.5f'),...
                                                    strvcat(num2str(ObjFinal,'%.4f'),repmat(' ',[numel(XiFinalAllPars)-1 1])),...
                                                    strvcat(num2str(ObjFinalAllMoms,'%.4f'),repmat(' ',[numel(XiFinalAllPars)-1 1])),...
                                                    strvcat(num2str(FlagFinal,'%.0f'),repmat(' ',[numel(XiFinalAllPars)-1 1])),...
                                                    strvcat(num2str(FevalsFinal,'%.0f'),repmat(' ',[numel(XiFinalAllPars)-1 1])));
    Table6.Properties.VariableNames         = ["Point estimate" "Obj. (targ.)" "Obj. (all)" "Flag" "Fevals"];
    Table6.Properties.RowNames              = {'xi','sigma','k','S','M_e','C'};
    disp(Table6)
    Table7                                  = table(num2str(M_full,'%.3f'),...
                                                    num2str(mean(OutputFinal.M,2),'%.3f'));
    Table7.Properties.VariableNames         = ["Emp. value" "Sim. value"];
    Table7.Properties.RowNames              = Nu.all_moments;
    disp(Table7)
end

%%%%%%%%%
% Output
%%%%%%%%%

output.XiFinalAllPars                       = XiFinalAllPars;
output.ObjFinal                             = ObjFinal;
output.ObjFinalAllMoms                      = ObjFinalAllMoms;
output.FlagFinal                            = FlagFinal;
output.FevalsFinal                          = FevalsFinal;
output.OutputFinal                          = OutputFinal;

end